package models;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.text.ParseException;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;


public class testDatabaseModel {
	
	class TestModel extends DatabaseModel {
		// parent is abstract

		@Override
		public String[] getDataHeaders() {
			String[] headers = {"data_1", "data_2"};
			return headers;
		}

		@Override
		public String[] getData() {
			String[] data = {"DATA_1", "DATA_2"};
			return data;
		}
	
	}
	
	private DatabaseModel model;
	
	@Before
	public void setUp() {
		model = new TestModel();
	}
	
	@Test
	public void testModelId() {
		int testId = 893245;
		model.setId(testId);
		assertEquals(testId, model.getId());
		
	}
	
	@Test(expected=RuntimeException.class)
	public void testErrorOnNoId() {
		 model.getId();
	}

	@Test(expected=RuntimeException.class)
	public void testErrorOnMultipleId() {
		 model.setId(151);
		 model.setId(152);
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public void testParseDBdate() throws ParseException {
		Date expected = new Date();
		expected.setTime(0);
		expected.setSeconds(0);
		expected.setMinutes(0);
		expected.setHours(0);
		expected.setDate(10);
		expected.setMonth(3);
		expected.setYear(110);
		assertEquals(expected, DatabaseModel.parseDbDate("2010-04-10"));
	}
	
	@Test
	public void testGetTodaysDate() throws ParseException {
		String dbDate = DatabaseModel.dbDateFormat.format(new Date()); 
		Date expected = DatabaseModel.parseDbDate(dbDate);
		assertEquals(expected, DatabaseModel.getTodaysDate());
	}
	
	@Test
	public void test_getDataString() {
		assertEquals("data_1='DATA_1', data_2='DATA_2'", model.getDataString());
	}
	
	@Test
	public void test_getSelectString() {
		assertEquals("data_1='DATA_1' AND data_2='DATA_2'", model.getSelectString());
	}
	
	@Test
	public void test_toString() {
		assertTrue(model.toString().contains(model.getDataString()));
	}
	
	@Test
	public void test_EqualsAndHashCode() {
		// TODO see client
		fail();
	}
}
